# 字符串编码
a = '字符串编码'.encode('utf-8')
print(a)
# 打印结果为：b'\xe5\xad\x97\xe7\xac\xa6\xe4\xb8\xb2\xe7\xbc\x96\xe7\xa0\x81'

# 字符串解码
b = a.decode('utf')
print(b)
# 打印结果为：字符串编码


# 字符串的crud
# Create（创建）
c = 'meng'
c += ' chu'
print(c)
# 打印结果为：meng chu

# Retrieve(检索)
print(c[1])
# 打印结果为：e

print(c.find('e'))
print(c.index('e'))
# 打印结果为：1

date = "2020-12-26"
print(date.startswith("2020"))
print(date.endswith("26"))
# 打印结果为：True

# Update（更新）
print(c.replace("chu", "xiang"))
# 打印结果为：meng xiang
d = c.split(",")
print(d)
# 打印结果为：['meng chu']
print(",".join(d))
# 打印结果为：meng chu

# DELETE（删除）
q = "     study, python     "
print(q.strip())
# 打印结果为：study, python



# 将content内容保存至本地
output = open("output.txt", "w", encoding="utf-8")
content = "hello, world"
output.write(content)
output.close()

input = open("output.txt", "r", encoding="utf-8")
content = input.read()
print(content)

output = open("output.txt", "a", encoding="utf-8")
content = "\nhello, python"
output.write(content)
output.close()


# 字符串格式化输出
m = "ping"
n = "pong"
print("play pingpong: {}, {}".format(m, n))
print("play pingpong: {0}, {1}, {0}, {1}".format(m, n))
print("play pingpong: {m}, {n}, {m}, {n}".format(m = "ping", n = "pong"))
print(f"play pingpong: {m}, {n}")

print("{:.2f}".format(3.1415926))

print("play pingpong: %s %s"%("ping", "pong"))




